package com.wzh.controll;

import com.wzh.pojo.Po.Title;
import com.wzh.service.Titleser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Controller
@RequestMapping("/title")
public class title {
	@Autowired
	private Titleser titleser;
	@PostMapping("/add")
	@ResponseBody
	public result add(@RequestBody Title title){
		System.out.println(title);
		boolean flag= titleser.add(title);
		String mes=flag!=false?"操作成功":"操作失败";
		Integer code=flag!=false?200:300;
		return new result(mes,code,title);
	}

	@PostMapping("/delete")
	@ResponseBody
	public result delete(@RequestBody Title title){
		System.out.println(title);
		boolean flag= titleser.delete(title);
		String mes=flag!=false?"操作成功":"操作失败";
		Integer code=flag!=false?200:300;
		return new result(mes,code,title);
	}


	@GetMapping("/gettitle")
	@ResponseBody
	public result gettitle(){

		List<Title> titles = titleser.get();
		String mes=titles!=null?"查询成功":"查询失败";
		Integer code=titles!=null?200:300;
		return new result(mes,code,titles);
	}
}
